package cn.stronglink.asset.module.alarm.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import com.baomidou.mybatisplus.plugins.Page;

import cn.stronglink.asset.model.AlarmType;
import cn.stronglink.asset.module.alarm.service.AlarmService;
import cn.stronglink.asset.module.alarm.vo.AlarmVo;
import cn.stronglink.suite.core.base.AbstractController;
import cn.stronglink.suite.core.log.annotation.OperateLog;
import cn.stronglink.suite.core.log.annotation.OperateLog.OpType;

@Controller
@RequestMapping(value = "alarm")
public class AlarmControler extends AbstractController {
	
	@Autowired
	private AlarmService alarmService;
	
	@RequestMapping(value = "qryTypes")
	public ResponseEntity<ModelMap> qryTypes(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response) {
		List<AlarmType> list = alarmService.getTypes();
		return setSuccessModelMap(modelMap, list);
	}
	
	@RequestMapping(value = "getAlarmByParams")
	public ResponseEntity<ModelMap> getAlarmByParams(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody Map<String, Object> params) {
		@SuppressWarnings("unchecked")
		Page<AlarmVo> page = (Page<AlarmVo>) super.getPage(params);
		Page<AlarmVo> list = alarmService.getAlarmByParams(page,params);
		return setSuccessModelMap(modelMap, list);
	} 
	
	@OperateLog(module = "告警信息管理",desc="处理告警", type = OpType.UPDATE)
	@RequestMapping(value = "handle")
	public ResponseEntity<ModelMap> handle(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody Map<String, Object> params) {
		alarmService.updageAlarmResult(params);
		return setSuccessModelMap(modelMap, null);
	} 
	
	@RequestMapping(value = "getAlarmResultById")
	public ResponseEntity<ModelMap> getAlarmResultById(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody Long params) {
		String result = alarmService.getAlarmResultById(params);
		return setSuccessModelMap(modelMap, result);
	} 
	
}
